{extend name='comm/base' /}

{block name='header'}
{include file='comm/header'}
{/block}

{block name='slider'}
{include file='comm/slider'}
{/block}

{block name='main'}
<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="#">会员管理</a>
                </li>
                <li class="active">标签</li>
            </ul><!-- /.breadcrumb -->
        </div>
        <div class="page-content">

            <div class="page-header">
                <h1>
                    会员管理
                    <small>
                        <i class="ace-icon fa fa-angle-double-right"></i>
                        新增标签
                    </small>
                </h1>
            </div><!-- /.page-header -->
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="tag_name" >标签名称</label>
                            <div class="col-sm-9">
                                <input type="text" id="tag_name" placeholder="标签名称" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right">正分值1</label>
                            <div class="col-sm-9">
                                <input type="text" id="positive_score1" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')" placeholder="正分值1" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right">正分值2</label>
                            <div class="col-sm-9">
                                <input type="text" id="positive_score2" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')" placeholder="正分值2" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right">负分值1</label>
                            <div class="col-sm-9">
                                <input type="text" id="negative_score1"  placeholder="负分值1" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right">负分值2</label>
                            <div class="col-sm-9">
                                <input type="text" id="negative_score2" placeholder="负分值2" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>

                        <div class="clearfix form-actions">
                            <div class="col-md-offset-3 col-md-9">
                                <button class="btn btn-primary" type="button" id="save_btn">
                                    保存
                                </button>
                            </div>
                        </div>

                        <div class="hr hr-24"></div>
                    </form>
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->
{/block}

{block name='footer'}
{include file='comm/footer'}
{/block}
{block name='script'}

<script src="__ace_js__/jquery-2.1.4.min.js"></script>

<!-- <![endif]-->
<!--[if IE]>
<script src="__ace_js__/jquery-1.11.3.min.js"></script>
<![endif]-->
<script type="text/javascript">
    if('ontouchstart' in document.documentElement) document.write("<script src='__ace_js__/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>
<script src="__ace_js__/bootstrap.min.js"></script>

<!-- ace scripts -->
<script src="__ace_js__/ace-elements.min.js"></script>
<script src="__ace_js__/ace.min.js"></script>
<script src="__ace_js__/chosen.jquery.min.js"></script>
<script lang="javascript">

$('#save_btn').click(function(){
    var tag_name = $('#tag_name').val();
    var positive_score1 = $('#positive_score1').val();
    var positive_score2 = $('#positive_score2').val();
    var negative_score1 = $('#negative_score1').val();
    var negative_score2 = $('#negative_score2').val();
    if(tag_name == ''){
          swal({
            type: 'warning', // 弹框类型
            title: '请输入标签名称', //标题
            confirmButtonColor: '#438EB9',// 确定按钮的 颜色
            confirmButtonText: '确定',// 确定按钮的 文字
        });
        return false;
    }
    if(positive_score1 == ''|| positive_score1==''||negative_score1==''||negative_score2==''){
        swal({
            type: 'warning', // 弹框类型
            title: '请将信息填写完整', //标题
            confirmButtonColor: '#438EB9',// 确定按钮的 颜色
            confirmButtonText: '确定',// 确定按钮的 文字
        });
        return false;
    }
    $.ajax({
        url:"{:url('admin.tag.store')}",
        type:'POST',
        dataType:'JSON',
        data:{'tag_name':tag_name,'positive_score1':positive_score1,'positive_score2':positive_score2,'negative_score1':negative_score1,'negative_score2':negative_score2},
        success:function(res){
            if(res.code == 1){
                swal({
                    type: 'success', // 弹框类型
                    title: '操作成功', //标题
                    confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                    confirmButtonText: '确定',// 确定按钮的 文字
                }).then((isConfirm) => {
                    //判断 是否 点击的 确定按钮
                    if (isConfirm.value) {
                        location.href = "{:url('admin.tag.index')}";
                    }
                });
            }else{
                swal({
                    type: 'warning', // 弹框类型
                    title:res.msg, //标题
                    confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                    confirmButtonText: '确定',// 确定按钮的 文字
                });
            }
            return false;
        },error:function(e){
            swal({
                type: 'error', // 弹框类型
                title:e.msg, //标题
                confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                confirmButtonText: '确定',// 确定按钮的 文字
            });
        }
    })
})


</script>
{/block}






